package map;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        String line = "Jingle bell, jingle bell, jingle all the way!";

        //解法一:
        Map<Character, Integer> map1 = new HashMap<>();

        for (int i = 0; i < line.length(); i++) {
            char c = line.charAt(i);
            if (map1.containsKey(c)) {
                map1.put(c, map1.get(c) + 1);
            } else {
                map1.put(c, 1);
            }
        }
        System.out.println(map1);

        //解法二:
        Map<Character, Integer> map2 = new HashMap<>();

        for (char c : line.toCharArray()) {
            map2.put(c, map2.containsKey(c) ? map2.get(c) + 1 : 1);
        }
        System.out.println(map2);

    }
}
